﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MLM.AdminCP.Class;
using MLM.Base;
using MLM.Data;

namespace MLM.AdminCP.Pages
{
    public partial class RecommendUser : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MLMDataContext ct = new MLMDataContext();
            RecommendLinkTxt.Text = CommonSettingHelper.GetCommonSetting(ct, CommonSettingsContstants.WEB_BASEURL) + "/AdminCP/Pages/Register.aspx?ref=" + Permission.GetCurrentUserId();
            SentRecommendBtn.Click += new EventHandler(SentRecommendBtn_Click);
        }

        void SentRecommendBtn_Click(object sender, EventArgs e)
        {
            MLMDataContext ct = new MLMDataContext();
            try
            {
                try
                {
                    var link = CommonSettingHelper.GetCommonSetting(ct, CommonSettingsContstants.WEB_BASEURL) + "/AdminCP/Pages/Register.aspx?ref=" + Permission.GetCurrentUserId();
                    AdminCP.Email.Send_Email(EmailTxt.Text, "Invite join!",
                                     CommonSettingHelper.GetCommonSetting(ct,
                                         CommonSettingsContstants.EMAIL_SENDRECOMMENDTEMPLATE).Replace("{{LINK}}", link));
                }
                catch (Exception)
                {

                }
                EmailTxt.Text = "";
                Message.ShowSuccess("Email sent!");
            }
            catch (Exception ex)
            {
                Message.ShowError(ex.Message);
            }
        }
    }
}